<template>


<div>
   <div id="top">
     <div id="position" @click="position()"><img src="/static/images/shouye_icon_dingwei_n.png"><label>{{shopName}}</label><img src="/static/images/icon_down_n.png"></div>
    <div class="qrcodeImg" id="qrcodeImg">

    </div>
    <div id="msg">刷码开门</div>
  </div>

   <div id="scanView" @click="scanAction()">
       <div class="line">
           <img src="/static/images/anmation_image.png">
       </div>
       <img src="/static/images/shou_icon_saoma_n.png">

   </div>

   <p>扫码自购</p>
   <div id="shopMarket">
    <label @click="turnScan()">{{shopCount}}</label>
    <img  src="/static/images/shouye_gouwuche.png">
    

</div>
</div>

</template>

<script>
    import router from '../router/router'
    import axios from 'axios'
    var bannerArr = new Array();
    var goodsArr = new Array();
    var shopCode = "";
    export default {
        beforeCreate() {
           // bannerArr = JSON.parse(store.get('bannerList'));
        },
        data: function() {
            return {
               shopName:"",
               shopCount:0
            }
        },
        created() {
            // head的修改
            //this.getGoodsList(); //
            this.shopName=store.get('shopName')!=""?store.get('shopName'):"定位失败";
            this.registered();
            this.shareFriend();
            this.$store.commit('changeIndexConf', {
                isFooter: true,
                isToast: false,
            })
        var ua = navigator.userAgent.toLowerCase();        
        var isAndroid = ua.indexOf('android') != -1;
        var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
            if (store.get('isReload')==""&&isIos) {
              store.set("isReload","xxx");
             window.location.reload();
           }
           if(isAndroid){
            store.set("isReload","xxx");
           }
        },
        components: {

        },
        beforeDestroy() {

        },
        computed: {},
        mounted: function() {
           
           this.getShopList();
           var userInfo = JSON.parse(store.get("userInfo"));
           this.createQrcode(userInfo.obj.barCode!=null?userInfo.obj.barCode:"");


            //   this.createQrcode("测试");
       
        },
        methods: {
            shareFriend: function() {
                var _self = this;
                
                wx.onMenuShareAppMessage({
                    title: '扫码自购', // 分享标题
                    desc: '小麦公社自助收银，省钱省时又省力', // 分享描述
                    link: location.host+'/auth.do', // 分享链接
                    imgUrl: 'http://upload.imxiaomai.com/gaiaUpload/2017/3/1/500f580124513c93bfd1e207ce23e542.jpg', // 分享图标
                    type: 'link', // 分享类型,music、video或link，不填默认为link
                    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                    success: function() {
                        // 用户确认分享后执行的回调函数

                        _self.$store.commit('changeIndexConf',   {  
                            isToast:  true,
                            toastTip:   "分享成功"                
                        });
                    },
                    cancel: function() {
                        // 用户取消分享后执行的回调函数
                        _self.$store.commit('changeIndexConf',   {      
                            isToast:  true,
                            toastTip:   "分享失败"                
                        });
                    }
                });
            },
            registered: function() {
                var xmUrl = location.href.split('#')[0];
                axios.get('/auth/signature.do?url=' + xmUrl)
                    .then(function(response) {
                        var xmappId = response.data.appId;
                        var xmtimestamp = response.data.timestamp;
                        var xmnonceStr = response.data.nonceStr;
                        var xmsignature = response.data.signature;
                        wx.config({
                            debug: false,
                            appId: xmappId,
                            timestamp: xmtimestamp,
                            nonceStr: xmnonceStr,
                            signature: xmsignature,
                            jsApiList: [
                                'checkJsApi',
                                'onMenuShareTimeline',
                                'onMenuShareAppMessage',
                                'onMenuShareQQ',
                                'onMenuShareWeibo',
                                'hideMenuItems',
                                'showMenuItems',
                                'hideAllNonBaseMenuItem',
                                'showAllNonBaseMenuItem',
                                'translateVoice',
                                'startRecord',
                                'stopRecord',
                                'onRecordEnd',
                                'playVoice',
                                'pauseVoice',
                                'stopVoice',
                                'uploadVoice',
                                'downloadVoice',
                                'chooseImage',
                                'previewImage',
                                'uploadImage',
                                'downloadImage',
                                'getNetworkType',
                                'openLocation',
                                'getLocation',
                                'hideOptionMenu',
                                'showOptionMenu',
                                'closeWindow',
                                'scanQRCode',
                                'chooseWXPay',
                                'openProductSpecificView',
                                'addCard',
                                'chooseCard',
                                'openCard'
                            ]
                        });
                    })
                    .catch(function(error) {
                        store.set("position", "XM0001");
                        router.push("/first");

                        _self.$store.commit('changeIndexConf',   {                    
                            isToast:  true,
                             toastTip:   "系统出现问题,请暂勿使用,谢谢配合"                
                        });

                    });

                wx.error(function(res) {
                    store.set("position", "XM0001");
                    router.push("/first");
                    _self.$store.commit('changeIndexConf',   {                    
                        isToast:  true,
                        toastTip:   "系统出现问题,请暂勿使用,谢谢配合"                
                    });
                });
                var _self = this;
                wx.ready(function() {
                   
                });
            },
           
         createQrcode: function(barcode) {
                jQuery(function() {
                    jQuery('#qrcodeImg').qrcode({
                        render: "canvas",
                        text: barcode,
                        height: 150,
                        width: 150,
                        background: "#ffd01b",
                        foreground: "#000"
                    });
                });

            },
        turnScan:function(){
           router.push("/scan/shopMarket");

          },
           position: function() {
                router.push("/position")

            },
            scanAction:function(){
                router.push("/scan/nomal")
            },
            getShopList: function() {
                var _self=this;
                axios.get('/cart/getCart.do?shopCode=' + store.get('position'))
                    .then(function(response) {
                   _self.shopCount=response.data.obj.num;
                    })
                    .catch(function(error) {

                    });

            }
        }
    }
</script>
<style lang="scss" scoped>
    @import "../../static/css/index.scss";
</style>
